package com.ymttest.database.sqlwapper.sqdistributor;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.sqdistributor.DistributionAgencyConfig;

public class DistributionAgencyConfigWrapper {
	
	SqlManager manager;

	public DistributionAgencyConfigWrapper() {
		manager = new SqlManager("sqdistributor");
	}

	@SuppressWarnings("unchecked")
	public DistributionAgencyConfig selectByPrimaryKey(Long id) {

		DistributionAgencyConfig distributionAgencyConfig = null;
		List<DistributionAgencyConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencyConfigMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencyConfig = result.get(0);
		}

		return distributionAgencyConfig;
	}
	
	@SuppressWarnings("unchecked")
	public DistributionAgencyConfig selectByMerchantId(Long merchantId) {

		DistributionAgencyConfig distributionAgencyConfig = null;
		List<DistributionAgencyConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencyConfigMapper.selectByMerchantId",
						merchantId);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencyConfig = result.get(0);
		}

		return distributionAgencyConfig;
	}
	
	@SuppressWarnings("unchecked")
	public DistributionAgencyConfig selectByMerchantIdAndAgencyType(Long merchantId, Integer agencyType) {

		HashMap<String, Object> map = new HashMap<>();
		
		map.put("merchant_id", merchantId);
		map.put("agency_type", agencyType);
		
		DistributionAgencyConfig distributionAgencyConfig = null;
		List<DistributionAgencyConfig> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencyConfigMapper.selectByMerchantIdAndAgencyType",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencyConfig = result.get(0);
		}

		return distributionAgencyConfig;
	}
	
	public static void main(String[] args) {
		
		DistributionAgencyConfigWrapper test = new DistributionAgencyConfigWrapper();

		System.out.println(test.selectByMerchantIdAndAgencyType(500861041L, 1).getId());
	}
}
